package pers.mtx.hmw.listener;

import pers.mtx.hmw.cache.SingleMap;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

@WebListener
public class MyHttpSessionListener implements HttpSessionListener {
    private static int onlineNum = 0;

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        onlineNum++;
        System.out.println("在线人数："+onlineNum);

    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        onlineNum--;
        SingleMap.getInstance().getMap().remove(se.getSession().getId());
        System.out.println("在线人数："+onlineNum);
    }

}